package cn.bdqn.service.impl;

import java.util.List;

import cn.bdqn.dao.NewsCommentDao;
import cn.bdqn.dao.NewsDao;
import cn.bdqn.dao.impl.NewsCommentDaoImpl;
import cn.bdqn.dao.impl.NewsDaoImpl;
import cn.bdqn.pojo.News;
import cn.bdqn.pojo.NewsCategory;
import cn.bdqn.pojo.NewsComment;
import cn.bdqn.service.NewsService;

public class NewsServiceImpl implements NewsService {

	private NewsDao newsDao = null;
	private NewsCommentDao newsCommentDao = null;
	public NewsServiceImpl(){
		newsDao = new NewsDaoImpl();
		newsCommentDao = new NewsCommentDaoImpl();
	}
	
	@Override
	public List<News> getNewsList() {
		// TODO Auto-generated method stub
		return newsDao.getNewsList();
	}

	@Override
	public boolean add(News news) {
		// TODO Auto-generated method stub
		return newsDao.add(news);
	}

	@Override
	public boolean update(News news) {
		// TODO Auto-generated method stub
		return newsDao.update(news);
	}

	/**
	 * 删除新闻操作：
	 * 删除该条新闻之前，须先删除该条新闻下所有评论，再删除新闻信息
	 */
	@Override
	public boolean delete(News news) {
		// TODO Auto-generated method stub
		boolean flag = false;
		NewsComment newsComment = new NewsComment();
		newsComment.setNewsId(news.getId());
		int i = newsCommentDao.deleteByNewsId(newsComment);
		if(i != -1){
			flag = newsDao.delete(news);
		}
		return flag;
	}

	@Override
	public int getNewsCountByCategoryId(NewsCategory newsCategory) {
		// TODO Auto-generated method stub
		return newsDao.getNewsCountByCategoryId(newsCategory);
	}

	@Override
	public News getNewsById(News news) {
		// TODO Auto-generated method stub
		return newsDao.getNewsById(news);
	}

	@Override
	public int getNewsCount(News news) {
		// TODO Auto-generated method stub
		return newsDao.getNewsCount(news);
	}

	@Override
	public List<News> getPageNewsList(int pageNo, int pageSize,News news) {
		// TODO Auto-generated method stub
		return newsDao.getPageNewsList(pageNo, pageSize,news);
	}

}
